from time import sleep

from loguru import logger

from basic.basic_driver import DRIVER
from page.page_main import PageMain



MAIN = PageMain()

import pytest
@pytest.fixture(autouse=True)
def run_run_caser():
    logger.info("{}开始运行用例{}".format("="*20, "="*20))
    DRIVER.activate_app("com.xiaomi.shop")
    yield
    logger.info("{}结束运行用例{}".format("="*20, "="*20))
    DRIVER.terminate_app("com.xiaomi.shop")

#
# @pytest.fixture(autouse=True)
# def start_run_app():
#     logger.info("{}开始运行用例{}".format("="*20, "="*20))
#     while DRIVER.current_activity != "com.xiaomi.shop.activity.MainTabActivity":
#         DRIVER.back()
#         sleep(3)
#     yield
#     logger.info("{}结束运行用例{}".format("="*20, "="*20))
#




def pytest_collection_modifyitems(session, config, items):
    """自定义文件执行顺序"""
    file_order = [
        'test_shopping.py',
        'test_service.py',
    ]
    priority_map = {}
    for index, filename in enumerate(file_order):
        priority_map[filename] = index

    def get_priority(item):
        filename = item.fspath.basename
        return priority_map.get(filename, len(file_order))

    items.sort(key=get_priority)